package com.care.mall.server.controller;

import java.util.List;
import javax.servlet.http.HttpServletResponse;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.PostMapping;
import org.springframework.web.bind.annotation.PutMapping;
import org.springframework.web.bind.annotation.DeleteMapping;
import org.springframework.web.bind.annotation.PathVariable;
import org.springframework.web.bind.annotation.RequestBody;
import org.springframework.web.bind.annotation.RequestMapping;
import org.springframework.web.bind.annotation.RestController;
import com.care.common.log.annotation.Log;
import com.care.common.log.enums.BusinessType;
import com.care.common.security.annotation.RequiresPermissions;
import com.care.mall.common.domain.MallSkuInfo;
import com.care.mall.server.service.IMallSkuInfoService;
import com.care.common.core.web.controller.BaseController;
import com.care.common.core.domain.Result;
import com.care.common.core.utils.poi.ExcelUtil;
import com.care.common.core.web.page.TableDataInfo;

/**
 * 商品规格Controller
 *
 * @author 李光耀负责
 * @date 2024-03-27
 */
@RestController
@RequestMapping("/skuInfo")
public class MallSkuInfoController extends BaseController
{
    @Autowired
    private IMallSkuInfoService mallSkuInfoService;

    /**
     * 查询商品规格列表
     */
    @RequiresPermissions("mall:skuInfo:list")
    @GetMapping("/list")
    public TableDataInfo list(MallSkuInfo mallSkuInfo)
    {
        startPage();
        List<MallSkuInfo> list = mallSkuInfoService.selectMallSkuInfoList(mallSkuInfo);
        return getDataTable(list);
    }

    /**
     * 导出商品规格列表
     */
    @RequiresPermissions("mall:skuInfo:export")
    @Log(title = "商品规格", businessType = BusinessType.EXPORT)
    @PostMapping("/export")
    public void export(HttpServletResponse response, MallSkuInfo mallSkuInfo)
    {
        List<MallSkuInfo> list = mallSkuInfoService.selectMallSkuInfoList(mallSkuInfo);
        ExcelUtil<MallSkuInfo> util = new ExcelUtil<MallSkuInfo>(MallSkuInfo.class);
        util.exportExcel(response, list, "商品规格数据");
    }

    /**
     * 获取商品规格详细信息
     */
    @RequiresPermissions("mall:skuInfo:query")
    @GetMapping(value = "/{skuId}")
    public Result getInfo(@PathVariable("skuId") Integer skuId)
    {
        return success(mallSkuInfoService.selectMallSkuInfoBySkuId(skuId));
    }

    /**
     * 新增商品规格
     */
    @RequiresPermissions("mall:skuInfo:add")
    @Log(title = "商品规格", businessType = BusinessType.INSERT)
    @PostMapping
    public Result add(@RequestBody MallSkuInfo mallSkuInfo)
    {
        return toAjax(mallSkuInfoService.insertMallSkuInfo(mallSkuInfo));
    }

    /**
     * 修改商品规格
     */
    @RequiresPermissions("mall:skuInfo:edit")
    @Log(title = "商品规格", businessType = BusinessType.UPDATE)
    @PutMapping
    public Result edit(@RequestBody MallSkuInfo mallSkuInfo)
    {
        return toAjax(mallSkuInfoService.updateMallSkuInfo(mallSkuInfo));
    }

    /**
     * 删除商品规格
     */
    @RequiresPermissions("mall:skuInfo:remove")
    @Log(title = "商品规格", businessType = BusinessType.DELETE)
	@DeleteMapping("/{skuIds}")
    public Result remove(@PathVariable Integer[] skuIds)
    {
        return toAjax(mallSkuInfoService.deleteMallSkuInfoBySkuIds(skuIds));
    }
}
